<template>
	<view>
		<mine-head title="后台保活设置"></mine-head>
		<view class="title-box">
			为了更好的使用无忧，建议您开启以下权限
		</view>
		<view class="list">
			<view class="item _df _ac _jb" @click="clickFn(item,index)" v-for="(item,index) in list" :key="index">
				<view class="text">
					<view class="title">
						{{item.title}}
					</view>
					<view class="info">
						{{item.content}}
					</view>
				</view>
				<view class="info">
					<u-icon class="ml20" name="arrow-right" color="#888" size="26"></u-icon>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	const keepAlive = uni.requireNativePlugin('Ba-KeepAliveSuit')
	export default {
		data() {
			return {
				list:[
					{
						title:'1、位置信息',
						content:'权限>位置信息>始终允许',
						value:'',
						path:'',
						type:1
					},
					{
						title:'2、后台弹窗',
						content:'权限>后台弹窗>允许',
						value:'',
						path:'',
						type:2
					},
					{
						title:'3、消息通知',
						content:'权限>通知管理>允许通知',
						value:'',
						path:'',
						type:3
					},
					{
						title:'4、麦克风',
						content:'权限>麦克风>允许',
						value:'',
						path:'',
						type:8
					},
					{
						title:'5、设置自启动、后台运行',
						content:'应用和服务>应用启动管理>无忧>关闭自动管理>允许自启动、允许后台活动',
						value:'',
						path:'',
						type:4
					},
					{
						title:'6、申请加入电池优化白名单',
						content:'无忧>不允许',
						value:'',
						path:'',
						type:5
					},
					{
						title:'7、开启后台保活',
						content:'开启后应用将常驻后台和通知栏',
						value:'',
						path:'',
						type:6
					}
					
					// {
					// 	title:'是否加入电池优化白名单',
					// 	value:'',
					// 	path:'',
					// 	type:4
					// },
					// {
					// 	title:'跳转到电池优化设置页',
					// 	value:'',
					// 	path:'',
					// 	type:5
					// },
					// {
					// 	title:'常驻通知保活',
					// 	value:'',
					// 	path:'',
					// 	type:6
					// },
					// {
					// 	title:'取消常驻通知保活',
					// 	value:'',
					// 	path:'',
					// 	type:7
					// },
					
				],
				user:{},
				cache_size:''
			};
		},
		onLoad() {
			
		},
		onShow() {
			
		},
		methods:{
			onKeep() { //通用保活
				keepAlive.onKeep({
						//channelId: "Ba-KeepAlive",
						//channelName: "Ba-KeepAlive",
						title: "无忧",
						content: "正在运行中···",
					},
					(res) => {
						console.log(res);
						uni.showToast({
							title: '已开启后台保活',
							icon: "none",
							duration: 3000
						})
					});
			},
			onAutoStart() { //去设置自启动、后台运行
				keepAlive.onAutoStart(
					(res) => {
						console.log(res);
						// uni.showToast({
						// 	title: res.msg,
						// 	icon: "none",
						// 	duration: 3000
						// })
					});
			},
			requestIgnoreBattery() { //申请加入电池优化白名单
				keepAlive.requestIgnoreBattery(
					res => {
						console.log(res);
						// uni.showToast({
						// 	title: res.msg,
						// 	icon: "none",
						// 	duration: 3000
						// })
					});
			},
			goIgnoreBattery() { //跳转到电池优化设置页
				keepAlive.goIgnoreBattery(
					res => {
						console.log(res);
						// uni.showToast({
						// 	title: res.msg,
						// 	icon: "none",
						// 	duration: 3000
						// })
					});
			},
			isIgnoringBattery() { //是否加入电池优化白名单
				keepAlive.isIgnoringBattery(
					res => {
						console.log(res);
						// if (res.data) {
						//  this.msgList.unshift(JSON.stringify(res.data))
						//  this.msgList.unshift(dateUtil.now())
						// }
						// uni.showToast({
						// 	title: res.msg,
						// 	icon: "none",
						// 	duration: 3000
						// })
					});
			},
			onShowNotify() { //常驻通知保活
				keepAlive.onShowNotify({
					//channelId: "Ba-KeepAlive",
					//channelName: "Ba-KeepAlive",
					//ID:99
					title: "测试",
					content: "正在运行中···",
				},
				(res) => {
					console.log(res);
					uni.showToast({
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			onCancelNotify() { //取消常驻通知保活
				keepAlive.onCancelNotify({
					//channelId: "Ba-KeepAlive",
					//channelName: "Ba-KeepAlive",
					//ID:99
					//title: "测试",
					//content: "常驻通知描述",
				},
				(res) => {
					console.log(res);
					uni.showToast({
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			toSetting(){
				uni.openAppAuthorizeSetting({//停止运行
					success: function () {
						console.log('打开系统设置页面成功');
					},
					fail: function () {
						console.log('打开系统设置页面失败');
					}
				});
			},
			clickFn(e,index){
				let that = this
				if(e.type == 1){//位置信息
					this.toSetting()
					
				}if(e.type == 2){//后台弹窗
					this.toSetting()
					
				}if(e.type == 3){//消息通知
					this.toSetting()
				}if(e.type == 4){//去设置自启动后台运行
					this.onAutoStart()
				}if(e.type == 5){//加入电池优化白名单
					this.goIgnoreBattery() 
				}if(e.type == 6){//通用保活
					this.onKeep()
				}
				if(e.type == 8){//
					this.toSetting()
				}
				if(e.type == 9){//
					
				}
				if(e.type == 10){//消息通知
					uni.$_setPermissions()
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.title-box{
		padding: 30rpx 30rpx 20rpx;
		font-size: 34rpx;
		color: #111;
		font-family: $uni-font-family-Bold;
	}
.list{
	padding: 0 50rpx;
	.item{
		border-bottom: 1rpx solid #e5e5e5;
		padding: 30rpx 0;
		.text{
			padding-right: 30rpx;
			.info{
				font-size: 28rpx;
				color: #666;
			}
			.title{
				font-size: 32rpx;
				color: #111;
				font-family: $uni-font-family-Bold;
				margin-bottom: 10rpx;
			}
		}
		
	}
}
.btn{
	margin: 30rpx 0;
}
/deep/.u-btn--primary{
		background-color: #6387FF;
		border-color: #6387FF;
	}
.btn-box{
	position: fixed;
	bottom: 40rpx;
	left: 0;
	width: 100%;
	padding: 0 50rpx;
	box-sizing: border-box;
}
</style>
